package com.logansoft.servicehomework.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author liqiye
 * @description elasticSearch 的 RestHighLevelClient 客户端的配置类
 * 这个配置类其实es源码里面也有，但是我们这里再次指定，并指定上连接信息。
 *  源码里面的方法名为elasticSearchRestHighLevelClient，这里叫restHighLevelClient
 *  到时候Autowired时，指定什么名字就会用哪个
 * @date 2021/07/15
 */

@Configuration
public class ElasticSearchConfig {

    @Bean
    public RestHighLevelClient restHighLevelClient(){
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(
                        new HttpHost("192.168.89.188", 9200,"http")
                        // new HttpHost("127.0.0.1", 9201,"http")  // 如果集群这里配置多个
                )
        );
        return client;
    }

}
